Sequences and Infinite Series

Introduction

In this notebook, we will learn about sequences, series, and convergence. First, we will use Mathematica to construct and plot terms of sequences, and to find the limits of sequences. We will see how Mathematica treats sequences that do not converge. Later, we will find the values of infinite series and construct partial sums. We will also show how to use the Integral Test to estimate the values of series.

Sequences

In Mathematica, finite sequences can be generated using the Table command. The first argument is the expression that defines the terms of the sequence, and the second argument is the range over which to evaluate the expression

s[n_]:=1/n^2
Table[s[n],{n,1,25}]

We can also define sequences recursively using RecurrenceTable. The first argument is a list of equations that must be satisfied (generally the recurrence relation and any initial conditions), the second argument is the dependent variable in the equations, and the final argument is the range over which to evaluate the expression:

RecurrenceTable[{f[n]==f[n-1]/2+1,f[1]==5},f,{n,1,25}]

We can visualize a sequence using the ListPlot command. Without any arguments, it produces a type of plot called a point plot:

ListPlot[Table[s[n],{n,1,25}],PlotRange-> All]

We can use the Filling option to make it more explicit which point goes where:

ListPlot[Table[s[n],{n,1,25}], Filling->Axis,PlotRange-> All]

We can also use the BarChart fuction to display everything as boxes instead of points:

BarChart[Table[s[n],{n,1,25}],BarSpacing-> None]

Infinite sequences are generated the same way as functions.

a[n_]:=7*n/(n^3+1)
a[1]
a[2]
a[3]
a[4]
a[5]

In order for the function we've defined to be treated as a sequence, we have to specify the domain as the natural numbers. This is done by passing the Assumptions option:

b[n_]:=Sin[Pi*n]
Table[b[n],{n,1,25}]
Limit[b[n],n-> Infinity]
Limit[b[n],n-> Infinity,Assumptions->{Element[n,Integers],n≥0}]

If a sequence is convergent, then its limit at infinity exists and is finite. A sequence is divergent if its limit at infinity is infinite. A sequence is neither convergent nor divergent if its limit at infinity does not exist, but isn't infinite either. When evaluating limits, Mathematica handles convergent sequences by giving the limit, divergent sequences by giving +±∞, and neither convergent nor divergent sequences by giving the region over which the sequence varies.

Limit[1/n,n-> Infinity,Assumptions->{Element[n,Integers],n≥0}]
Limit[n,n-> Infinity,Assumptions->{Element[n,Integers],n≥0}]
Limit[Sin[n],n-> Infinity,Assumptions->{Element[n,Integers],n≥0}]

Series

We define infinite series in Mathematica the same way that we write them in class, by writing the upper limit of a sum as infinity:

Sum[(1/2)^n,{n,1,Infinity}]

Nonconvergent series are not handled the same way as with sequences:

Sum[1/n,{n,1,Infinity}]
Sum[Sin[(Pi/2)*n],{n,1,Infinity}]

Regardless of whether the series converges, we can define a sequence consisting of the partial sum of a series out to some number of terms:

partialsum[n_]:=Sum[(1/2)^i,{i,1,n}]

The first few terms (starting with index 1) of the sequence of partial sums, and the numerical approximation of the 5th partial sum, are:

Table[partialsum[n],{n,1,10}]
N[partialsum[5]]

We can then take the limit of this sequence of partial sums to get some idea of how the series behaves:

Limit[partialsum[n],n-> Infinity]

IMPORTANT: The limit of the sequence of partial sums is NOT the same as the limit of the sequence of terms in the sum. The terms of the sum are (((1/2))^i), where i≥1. And the first few sequence of terms of the sum, and the limit of the sum, are:

Table[(1/2)^i,{i,1,10}]
Limit[(1/2)^i,i->Infinity,Assumptions->{Element[n,Integers],n≥0}]

In fact, it is a theorem that if the sequence of terms of the series does not converge to zero, then the series must diverge.

A nonconvergent example would look like this:

nonconvergentpartialsum[n_]:=Sum[Sin[(Pi/2)*i],{i,1,n}]
Limit[nonconvergentpartialsum[n],n-> Infinity]

We can check for convergence with the integral test:

Limit[Integrate[(1/2)^n,{n,1,x}],x-> Infinity]
Limit[Integrate[1/n,{n,1,x}],x-> Infinity]
Limit[Integrate[Sin[(Pi/2)*n],{n,1,x}],x-> Infinity]

We can also obtain an estimate of the error between a partial sum and the true sum using the integral test. To understand how this works, let's look at a plot of a function and the sequence generated from the function::

a[x_]:=7*x/(x^3+1)
Show[BarChart[Table[a[n],{n,1,50}],PlotRange-> {{1,50},{0,0.25}},BarSpacing-> None],Plot[a[x],{x,1,50},PlotStyle-> Red,PlotRange-> {{1,50},{0,0.25}}]]

The sequence values are represented by the boxes, while the function values are represented by the red line. The series consisting of the sum over this sequence would be the area of the boxes. The integral would be the area under the red line. As we can see, the sequence and function correspond, but not the series and integral. However, the error between the series and the integral depends on the function values. For convergent series, this means that the integral's value is a closer approximation for a series' value over the same regions, the further away from the origin we get.

Let's look at the same plot from a different perspective:

Show[BarChart[{Table[a[n],{n,1,25}],Table[a[n],{n,26,50}]},PlotRange-> {{0,50},{0,0.25}},BarSpacing-> None,ChartStyle-> {{LightBlue,Blue},None}],Plot[a[x],{x,0,50},PlotStyle-> Red,PlotRange-> {{0,50},{0,0.25}}]]

Comparing the integral over the region from 1 to 25, to the area enclosed by the light blue rectangles, we see there are errors. However, if we compare the integral over the region from 26 to 50 to the dark blue rectangles, the errors are much less in magnitude. If we extend the dark blue rectangles to infinity, then we can estimate the difference between a partial sum (The area of the light blue rectangles) and the full sum (The area of all the rectangles) by the integral of the function over the region encompassed by the dark blue rectangles.

Exercises

Assignment 1: Evaluating Series

Use Mathematica to evaluate the following series:

(∑_(n=1)^∞)((((e/π)))^n)

(∑_(n=1)^∞)((6(n^2)+2n-1)/(n(n+1)(4(n^2)-1)))

Your answer should be the values for the two series.

Assignment 2: Evaluating Partial Sums

Determine via trial and error the number of terms of the Harmonic Series (∑_(n=1)^∞)(1/n) for which the partial sums exceed 5, 8, and 11, and comment on these values. Your answer should include:

The amounts of terms needed to exceed 5, 8, and 11.

A conjecture as to how fast the amount of terms grows with the value to exceed (e.g. logarithmically, linearly, quadratically, exponentially, etc).

Assignment 3:  An Alternating Series

Investigate the Alternating Harmonic Series(∑_(n=1)^∞)((((-1))^n)/n), and calculate a partial sum that is within 0.001 of the infinite sum. Your answer should include:

A Point or Bar plot of the sequence ((((-1))^n)/n), which shows at least the first eight elements.

A Point or Bar plot of the sequence of partial sums (∑_(i=1)^n)((((-1))^i)/i), which show at least the first eight elements.

An estimate of the difference between the fourth partial sum and the value of the series itself, obtained from the plots above.

An explanation of how the estimate above relates to the plots above.

A calculation of a partial sum  (∑_(i=1)^N)((((-1))^i)/i) that is within 0.001 of the value of the series.

An explanation of how N was obtained.

Assignment 4:  Using the Integral Test

Use the Integral Test to assist with estimating the series (∑_(n=1)^∞)((ln n)/(n^2)), and calculate a partial sum that is within 0.001 of the infinite sum. Your answer should include:

A Bar plot of the sequence ((ln n)/(n^2)) which shows at least the first eight elements and a plot of the function ((ln x)/(x^2)) on the same axes.

A statement of how the integral  (∫_a^b)((ln x)/(x^2))dx is related to the sum  (∑_(n=a)^b)((ln n)/(n^2)), provided a and b are integers and b>a>1.

Calculations of the partial sums (∑_(n=1)^25)((ln n)/(n^2)) and (∑_(n=1)^50)((ln n)/(n^2)).

Estimates of the differences between the partial sums above and the value of the series (∑_(n=1)^∞)((ln n)/(n^2)), obtained via integration.

A calculation a partial sum  (∑_(n=1)^N)((ln n)/(n^2)) that is within 0.001 of the value of the series.

An explanation of how N was obtained.